package composite;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

/**
 * @Author: Ma JiBin
 * @Email: 1423553596@qq.com
 * @Date: 2018/9/7 11:16
 * @Description: 组合模式（Composite Pattern），又叫部分整体模式
 */
public class Main {
    public static void main(String[] args) {
        Employee CEO = new Employee("马云", "CEO", 30000);
        Employee headSales = new Employee("马化腾", "法人代表", 30000);
        Employee headMarketing = new Employee("王二", "销售经理", 20000);
        Employee clerk1 = new Employee("Laura", "Marketing", 10000);
        Employee clerk2 = new Employee("Bob", "Marketing", 10000);

        Employee salesExecutive1 = new Employee("Richard", "Sales", 10000);
        Employee salesExecutive2 = new Employee("Rob", "Sales", 10000);

        CEO.add(headSales);
        CEO.add(headMarketing);

        headSales.add(salesExecutive1);
        headSales.add(salesExecutive2);

        headMarketing.add(clerk1);
        headMarketing.add(clerk2);

        /**
         * 打印所有员工
         */
        System.out.println(CEO);
        for (Employee employee1 : CEO.getSubordinates()) {
            System.out.println(employee1);
            for (Employee employee2 : employee1.getSubordinates()) {
                System.out.println(employee2);
            }
        }

    }
}
